package com.example.goodsmanagementcabinet.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class DateUtils
{

    public DateUtils()
    {
    }

    private static final DateUtils dateUtils = new DateUtils();

    public static DateUtils getInstance()
    {
        return dateUtils;
    }

    public String format(Date date)
    {
        String format = "yyyy-MM-dd";
        SimpleDateFormat fmt = new SimpleDateFormat(format);
        return fmt.format(date);
    }

    private String format(Date date, String format)
    {
        SimpleDateFormat fmt = new SimpleDateFormat(format);
        return fmt.format(date);
    }

    private Date parse(String date, String format)
            throws ParseException {
        SimpleDateFormat fmt = new SimpleDateFormat(format);
        return fmt.parse(date);
    }

    public String getToday()
    {
        String result = "";
        Date date = new Date();
        result = format(date);
        return result;
    }

    public String getTime()
    {
        String result = "";
        Date date = new Date();
        result = format(date, "yyyy-MM-dd HH:mm:ss");
        return result;
    }

    public String getTimeNoSeparate()
    {
        String result = "";
        Date date = new Date();
        result = format(date, "yyyyMMddHHmmss");
        return result;
    }

    public String getNow()
    {
        String result = "";
        Date date = new Date();
        Calendar.getInstance(Locale.getDefault());
        int year = 1;
        Calendar.getInstance(Locale.getDefault());
        int month = 2;
        Calendar.getInstance(Locale.getDefault());
        int day = 5;
        Calendar.getInstance(Locale.getDefault());
        int week = 7;
        result = format(date, "yyyyMMdd");
        return result;
    }

    public Date format(String str)
    {
        Date result = null;
        try
        {
            str = str + " ";
            int endStr = str.indexOf(" ");
            String dateString = str.substring(0, endStr);
            result = parse(dateString, "yyyy-MM-dd");
        }
        catch(Exception ex) { }
        return result;
    }



}

